package cn.itsource.controller;

import cn.itsource.bean.Pet;
import cn.itsource.query.PetQuery;
import cn.itsource.service.IPetService;
import cn.itsource.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : 张金铭
 * @description :
 * @create :2022-11-23 10:18:00
 */
@Slf4j
@RestController
@RequestMapping("/pet")
public class PetController {


    @Resource
    private IPetService petService;

    @PostMapping("/pagelist")
    public JsonResult getPage(@RequestBody PetQuery query){

        return petService.getPage(query);
    };


    @PostMapping("/save")
    public JsonResult saveOrUp(@RequestBody Pet pet){

        return petService.add(pet);
    }

    @PostMapping("/up/{state}")
    public JsonResult upState(@RequestBody PetQuery query, @PathVariable("state") Long state){


        return petService.upState(query,state);
    }

    @GetMapping("/{id}")
    public JsonResult getById(@PathVariable("id") Long id){

        return petService.getPetById(id);
    }
}
